
#include "rindexd.h"

Err rp_rindexd_getopt(argc, argv)
{
	Err err;

	return err;
}

void rp_rindexd_env_init()
{
	struct stat envstat;
	
	if ((env.cfgdir = getenv("RP_CFG_DIR")))
	{
		if (stat(env.cfgdir, &envstat) < 0) 
		{
			env.cfgdir = "/etc/rally/bin";
		}		
	} else {
		env.cfgdir = "/etc/rally/bin";
	}
	if (stat(env.cfgdir, &envstat) < 0) 
	{
		exit(127);
	}
	
	if ((env.bindir = getenv("RP_BIN_DIR")))
	{
		if (stat(env.bindir, &envstat) < 0) 
		{
			env.bindir = "/etc/rally/bin";
		}		
	} else {
		env.bindir = "/etc/rally/bin";
	}
	if (stat(env.bindir, &envstat) < 0) 
	{
		exit(127);
	}		
}

void rp_rindexd_config_init();

void rp_rindexd_global_init()
{
	char fname[] = "rp_rindexd_global_init";
	char msg[] = "fatal message";
	Err err;
	FLOG_IN(fname);

	global.status_sched = (Status*)calloc(config.num_thread_prestart, sizeof(Status));
	Status *status = global.status_sched;
	int i;
	for (i=0; i<config.num_thread_prestart; i++)
	{
		if (rp_mutex_init(&(status+i)->mutex) != E_OK)
		{
			rp_log(LOG_DEBUG, fname, "Cannot initialize %dth scheduler status mutex ...", i);
		}	
	}
	err = rp_mutex_init(&(global.mutex_sched));
	
	
	FLOG_OUT(fname);
	return;
}

void rp_rindexd_log_init()
{
	char fname[] = "rp_rindexd_log_init";
	char msg[] = "fatal error";
	Err err;

	if (rp_log_init(config.logdir, "rindexd", config.loglv) != E_OK) exit(127);	
}

